﻿using System;
using System.Collections.Generic;
using System.Text;
using Gestion.Domain.Entities;
using Gestion.Core.Service.Business;
using Gestion.Core.Data.Dao;
using Gestion.Data.Dao;

namespace Gestion.Service.Business
{
    public class RiesgoService : Generic.GenericBusinessService<RiesgoEntity, Int64?, RiesgoDao>, IRiesgoService
    {

        private IDetalleRiesgoDao _detalleRiesgoDao;
        public IDetalleRiesgoDao DetalleRiesgoDao
        {
            get
            {
                return _detalleRiesgoDao;
            }
            set
            {
                _detalleRiesgoDao = value;
            }
        }
        
        public void CreateRiesgoAndDetalles(RiesgoEntity riesgo)
        {
            Dao.Save(riesgo);

            foreach (DetalleRiesgoEntity detalleRiesgo in riesgo.DetalleRiesgoCollection)
            {                
                detalleRiesgo.Riesgo = riesgo;
                DetalleRiesgoDao.Save(detalleRiesgo);
            }
        }

        public bool IsHasDetailsRisks(RiesgoEntity riesgo)
        {
            if (riesgo.DetalleRiesgoCollection.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }       
    }
}
